package com.huiquan.icd.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.icd.domain.IcdDiseaseExternal;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class IcdDiseaseExternalDao extends EnhancedBaseDao<IcdDiseaseExternal> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "ICD_DISEASE_EXTERNAL.";

	public IcdDiseaseExternalDao() {
		super(space);
	}
	
	public void initShowDisease() {
		this.update(space + "INIT_SHOW_DISEASE", sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<String> getAllDiseaseName(){
		return (List<String>)this.list(space + "RETRIEVE_ALL_DISEASE_NAME", sqlMapClient) ;
	}
	@SuppressWarnings("unchecked")
	public List<String> getAllDiseaseNameWithOutSynonymy(Map<String, Object> param){
		return (List<String>)this.list(space + "RETRIEVE_ALL_DISEASE_NAME2",param, sqlMapClient) ;
	}
	@SuppressWarnings("unchecked")
	public List<String> getAllExternalDisease(){
		return (List<String>)this.list(space + "RETRIEVE_DISEASE", sqlMapClient) ;
	}
	public void initBeforeBatchInsert() {
		this.update(space + "INIT_BEFORE_BATCH_INSERT", sqlMapClient);
	}
	public void updateExample() {
		this.update(space + "UPDATE_EXAMPLE", sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<IcdDiseaseExternal> retrievesExportList() {
		return (List<IcdDiseaseExternal>)this.list(space + "RETRIEVE_EXPORT_LIST", sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<IcdDiseaseExternal> retrievesExportTZList() {
		return (List<IcdDiseaseExternal>)this.list(space + "RETRIEVE_DISEASE_EXTERNAL_TZ", sqlMapClient);
	}
	public void updateCheckFlag(long id) {
		this.update(space + "UPDATE_CHECK_FLAG_BY_ID",id, sqlMapClient);
	}
	public void batchInsert(List<IcdDiseaseExternal> externalList) {
		Map<String, Object> param = new HashMap<>();
		int start = 0, end, size = externalList.size();
		List<IcdDiseaseExternal> tempList;

		while (start < size) {
			if (start + 2000 < size) {
				end = start + 2000;
			} else {
				end = size;
			}
			tempList = externalList.subList(start, end);
			param.put("list", tempList);
			this.insert(space + "BATCH_INSERT", param, sqlMapClient);
			start += 2000;
		}
	}
	public void updateDisable(String showDisease , String disable) {
		Map<String, Object> param = new HashMap<>();
		param.put("showDisease", showDisease);
		param.put("disable", disable);
		this.update(space + "UPDATE_DISABLE", param,sqlMapClient);
	}
	public void updateCategory(String showDisease , String category) {
		Map<String, Object> param = new HashMap<>();
		param.put("showDisease", showDisease);
		param.put("category", category);
		this.update(space + "UPDATE_CATEGORY", param,sqlMapClient);
	}
	public void updateAll(Map<String, String> param) {
		this.update(space + "UPDATE_ALL", param,sqlMapClient);
	}
}
